home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Text Editor / Source / TextEditorTransferExt.cpp < prev    next >
Encoding:
Text File  |  1995-12-13  |  9.4 KB  |  343 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TextEditorTransferExt.cpp
  3.  
  4.     Contains:    Text Transfer Extension for TextEditor part.
  5.  
  6.     Written by:    Troy Gaul
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Issues:        Additional methods that may be needed include:
  11.                 - InsertText
  12.                 - ReplaceSelection
  13.                 
  14.                 Both of the above methods may have the implementation in the data-transfer
  15.                 extension, e.g. no call to the owner part to do the above, just a GetPartData
  16.                 call, followed by inserting or replacing text in the local copy, and then a
  17.                 SetPartData call to the owner part.  Or, the above calls can be made similar to
  18.                 GetData and SetData, just handling of the ODByteArray packaging.  The first 
  19.                 alternative is prob. the best, since it would be easy to rip out the code and
  20.                 replace it with the proper calls to the owner part.
  21. */
  22.  
  23. // Notification that this is a SOM source file
  24. #define TextEditorTransferExt_Class_Source
  25.  
  26. // define underscore field names (e.g. _fSelf)
  27. #define VARIABLE_MACROS
  28.  
  29.  
  30. #ifndef _COMPILERDEFS_
  31. #include "CompDefs.h"
  32. #endif
  33.  
  34. // -- OpenDoc Utilities --
  35.  
  36. #ifndef _EXCEPT_
  37. // Exceptions define several important macros (e.g. CHECKENV)
  38. // which are used in the SOM method dispatch glue. If Except.h
  39. // is not included early enough, exceptions may not be thrown
  40. // correctly when returning from a SOM method with "ev" parameter set.
  41. #include <Except.h>
  42. #endif
  43.  
  44. // -- TextEditorTransferExt Includes --
  45.  
  46. #ifndef SOM_TextEditorTransferExt_xih
  47. #include "TextEditorTransferExt.xih"
  48. #endif
  49.  
  50. // -- TextEditor Includes --
  51.  
  52. #ifndef SOM_SampleCode_TextEditor_xh
  53. #include "TextEditor.xh"
  54. #endif
  55.  
  56. // -- OpenDoc Includes --
  57.  
  58. #ifndef _ODTYPES_
  59. #include <ODTypes.h>
  60. #endif
  61.  
  62. #ifndef SOM_ODExtension_xh
  63. #include <Extensn.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODPlatformTypeList_xh
  67. #include <PfTypLs.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODPlatformTypeListIterator_xh
  71. #include <PfTLItr.xh>
  72. #endif
  73.  
  74. // -- OpenDoc Utilities --
  75.  
  76. #ifndef _TEMPITER_
  77. #include <TempIter.h>
  78. #endif
  79.  
  80. #ifndef _TEMPOBJ_
  81. #include <TempObj.h>
  82. #endif
  83.  
  84. #ifndef _ODDEBUG_
  85. #include <ODDebug.h>
  86. #endif
  87.  
  88. #ifndef _ODMEMORY_
  89. #include <ODMemory.h>
  90. #endif
  91.  
  92. #ifndef _BARRAY_
  93. #include <BArray.h>
  94. #endif
  95.  
  96. #ifndef _ODUTILS_
  97. #include <ODUtils.h>
  98. #endif
  99.  
  100. #pragma segment somTextEditorTransferExt
  101.  
  102. //==============================================================================
  103. // TextEditorTransferExt
  104. //==============================================================================
  105.  
  106. //------------------------------------------------------------------------------
  107. // Method:        somInit
  108. // Origin:        SOMObject
  109. //
  110. // Description:    This is the SOM equivalent of a C++ class constructor.
  111. //
  112. // Warnings:    You are not allowed to throw an exception from this method.
  113. //------------------------------------------------------------------------------
  114. SOM_Scope    void  
  115. SOMLINK        TextEditorTransferExt__somInit
  116.             (
  117.                 TextEditorTransferExt *somSelf
  118.             )
  119. {
  120. //    TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
  121.     TextEditorTransferExtMethodDebug("TextEditorTransferExt","somInit");
  122.  
  123.     // somInit and somUninit methods behave like C++ constructors in that the
  124.     // inherited methods are called automatically.
  125.     // Thus, there is no need to call the parent class' somInit or somUninit.
  126.     
  127.     // There is also no need to set instance variables to zero/NULL
  128.     // since SOM guarantees that a newly constructed object is zeroed.
  129. }
  130.  
  131. //------------------------------------------------------------------------------
  132. // Method:        somUninit
  133. // Origin:        SOMObject
  134. //
  135. // Description:    This is the SOM equivalent of a C++ class destructor.
  136. //
  137. // Warnings:    You are not allowed to throw an exception from this method.
  138. //------------------------------------------------------------------------------
  139. SOM_Scope    void
  140. SOMLINK        TextEditorTransferExt__somUninit
  141.             (
  142.                 TextEditorTransferExt *somSelf
  143.             )
  144. {
  145. //    TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
  146.     TextEditorTransferExtMethodDebug("TextEditorTransferExt","somUninit");
  147. }
  148.  
  149. //------------------------------------------------------------------------------
  150. // Method:        Release
  151. // Origin:        ODRefCntObj
  152. //------------------------------------------------------------------------------
  153. SOM_Scope    void
  154. SOMLINK        TextEditorTransferExt__Release
  155.             (
  156.                 TextEditorTransferExt*    somSelf, 
  157.                 Environment*            ev
  158.             )
  159. {
  160. //    TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
  161.     TextEditorTransferExtMethodDebug("TextEditorTransferExt","Release");
  162.  
  163.     TextEditorTransferExt_parent_TextTransferExt_Release(somSelf,ev);
  164. }
  165.  
  166. //------------------------------------------------------------------------------
  167. // Method:        InitTextEditorTransferExt
  168. // Origin:        TextEditorTransferExt
  169. //------------------------------------------------------------------------------
  170. SOM_Scope    void
  171. SOMLINK        TextEditorTransferExt__InitTextEditorTransferExt
  172.             (
  173.                 TextEditorTransferExt*    somSelf, 
  174.                 Environment*            ev,
  175.                 ODPart*                    owner
  176.             )
  177. {
  178.     TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
  179.     TextEditorTransferExtMethodDebug("TextEditorTransferExt","InitTextEditorTransferExt");
  180.     
  181.     SOM_TRY
  182.         somSelf->InitTextTransferExt(ev, owner);
  183.         
  184.         _fOwner = (SampleCode_TextEditor*) owner->GetRealPart(ev);
  185.     SOM_CATCH_ALL
  186.     SOM_ENDTRY
  187. }
  188.  
  189. //------------------------------------------------------------------------------
  190. // Method:        GetData
  191. // Origin:        DataTransferExt
  192. //
  193. // Description:    Called by client part to obtain data from the extensions owner.
  194. //                Returns the first type of data from the ODTypeList which the owner
  195. //                supports by creating an ODByteArray, storing the data with the above
  196. //                header and then returning a pointer to the ODByteArray (or null)
  197. //------------------------------------------------------------------------------
  198. SOM_Scope    ODBoolean
  199. SOMLINK        TextEditorTransferExt__GetData
  200.             (
  201.                 TextEditorTransferExt*    somSelf, 
  202.                 Environment*            ev,
  203.                 ODPlatformType            type,
  204.                 ODByteArray*            data
  205.             )
  206. {
  207.     TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
  208.     TextEditorTransferExtMethodDebug("TextEditorTransferExt","GetData");
  209.  
  210.     ODBoolean supportsType = kODFalse;
  211.  
  212.     SOM_TRY
  213.     
  214.         // Note: TextEditor owns the block that is returned.  Do not dispose
  215.         // of this pointer.
  216.         
  217.         ODPtr thePtr = kODNULL;
  218.         ODULong theSize = 0;
  219.         supportsType = _fOwner->GetText(ev, type, &thePtr, &theSize);
  220.         
  221.         // If GetText returned a valid pointer, then repackage the
  222.         // data into a ODByteArray.
  223.         if ( thePtr != kODNULL )
  224.         {
  225.             data->_buffer = (octet*) ODNewPtrClear(theSize);
  226.             ODBlockMove(thePtr, data->_buffer, theSize);
  227.             
  228.             data->_length = data->_maximum = theSize;
  229.         }
  230.         
  231.     SOM_CATCH_ALL
  232.     SOM_ENDTRY
  233.  
  234.     return supportsType;
  235. }
  236.  
  237. //------------------------------------------------------------------------------
  238. // Method:        SetData
  239. // Origin:        DataTransferExt
  240. //
  241. // Description:    Sets the data of the owner part to the data passed in the 
  242. //                 ODByteArray.
  243. //------------------------------------------------------------------------------
  244.  
  245. SOM_Scope    ODBoolean  
  246. SOMLINK        TextEditorTransferExt__SetData
  247.             (
  248.                 TextEditorTransferExt*    somSelf, 
  249.                 Environment*            ev,
  250.                 ODPlatformType            type,
  251.                 ODByteArray*            data
  252.             )
  253. {
  254.     TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
  255.     TextEditorTransferExtMethodDebug("TextEditorTransferExt","SetData");
  256.     
  257.     ODBoolean supportsType = kODFalse;
  258.  
  259.     SOM_TRY
  260.     
  261.         supportsType = _fOwner->SetText(ev, type, data->_buffer, data->_length);
  262.  
  263.     SOM_CATCH_ALL
  264.     SOM_ENDTRY
  265.  
  266.     return supportsType;
  267. }
  268.  
  269. //------------------------------------------------------------------------------
  270. // Method:        GetSelection
  271. // Origin:        TextTransferExt
  272. //
  273. // Description:    This method needs to be customized for the specific owner part.
  274. //------------------------------------------------------------------------------
  275.  
  276. SOM_Scope    ODBoolean
  277. SOMLINK        TextEditorTransferExt__GetSelection
  278.             (
  279.                 TextEditorTransferExt*    somSelf, 
  280.                 Environment*            ev,
  281.                 ODULong*                start,
  282.                 ODULong*                end
  283.             )
  284. {
  285. //    TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
  286.     TextEditorTransferExtMethodDebug("TextEditorTransferExt","GetSelection");
  287.  
  288.     ODBoolean result = kODFalse;
  289.  
  290.     SOM_TRY
  291.     
  292.         // Needs to be customized to call the appropriate method of the owner part,
  293.         // and then return the start and ending points of the selection.
  294.         WARN("TextEditorTransferExt::GetSelection unimplemented");
  295.         
  296.         // Return true of false depending on the success of the operation.
  297.         result = kODTrue;
  298.             
  299.     SOM_CATCH_ALL
  300.         result = kODFalse;
  301.     SOM_ENDTRY
  302.  
  303.     return result;
  304. }
  305.  
  306. //------------------------------------------------------------------------------
  307. // Method:        SetSelection
  308. // Origin:        TextTransferExt
  309. //
  310. // Description:    This method needs to be customized for the specific owner part.
  311. //------------------------------------------------------------------------------
  312.  
  313. SOM_Scope    ODBoolean  
  314. SOMLINK        TextEditorTransferExt__SetSelection
  315.             (
  316.                 TextEditorTransferExt*    somSelf, 
  317.                 Environment*            ev,
  318.                 ODULong                    start,
  319.                 ODULong                    end
  320.             )
  321. {
  322. //    TextEditorTransferExtData *somThis = TextEditorTransferExtGetData(somSelf);
  323.     TextEditorTransferExtMethodDebug("TextEditorTransferExt","SetSelection");
  324.  
  325.     ODBoolean result = kODFalse;
  326.  
  327.     SOM_TRY
  328.     
  329.         // Needs to be customized to call the appropriate method of the owner part,
  330.         // and then set the start and ending points of the selection.
  331.         WARN("TextEditorTransferExt::SetSelection unimplemented");
  332.     
  333.         // Return true of false depending on the success of the operation.
  334.         result = kODTrue;
  335.             
  336.     SOM_CATCH_ALL
  337.         result = kODFalse;
  338.     SOM_ENDTRY
  339.  
  340.     return result;
  341. }
  342.  
  343.